﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace PIMS.WorkPlugin.WMS
{
    public class WMSHttp
    {
        public static string HttpPost(string url, string body)
        {
            try
            {
                Encoding encoding = Encoding.UTF8;
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                request.Method = "POST";
                //request.Accept = "text/html, application/xhtml+xml, */*";
                request.ContentType = "application/json;charset=utf-8";

                byte[] buffer = encoding.GetBytes(body);
                request.ContentLength = buffer.Length;
                request.GetRequestStream().Write(buffer, 0, buffer.Length);
                using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                {
                    using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
                    {
                        string responseString = reader.ReadToEnd();
                        return responseString;
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception($"接口:{ex.Message}，接口报文：{body}");
            }
        }
    }
}
